package uk.ac.aber.Blockmation.Actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import uk.ac.aber.Blockmation.MainFrame;

/**
 * 
 * @author tom, aron
 */

public class ActionToggleGrid extends AbstractAction {
	
    private MainFrame mainFrame;
    private String pathOn = "../icons/ToggleGridOn.gif";
    private String pathOff = "../icons/ToggleGridOff.gif";

    public ActionToggleGrid(MainFrame mainFrame) {
        super("Toggle Grid"); 
        this.mainFrame = mainFrame;
        
        // the below from settings class file or?!
        //putValue(SHORT_DESCRIPTION, tooltip);  // Will appear as tooltip text.
        //putValue(MNEMONIC_KEY, new Integer(mnemonic));
        
    }
        
    public void actionPerformed(ActionEvent e) {
        
    	boolean isOn = mainFrame.getPad().isGridOn();
        
    	if (isOn) {
            mainFrame.getPad().showGrid(false);
            setImage();
        }
    	else {
            mainFrame.getPad().showGrid(true);
            setImageOff();
        }

    }
    
    public void setImage() {
        CreateImageIcon createImageIcon = new CreateImageIcon();
        putValue(SMALL_ICON, createImageIcon.create(pathOn));
    }
    
    public void setImageOff() {
        CreateImageIcon createImageIcon = new CreateImageIcon();
        putValue(SMALL_ICON, createImageIcon.create(pathOff));
    }

}
